package linter.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import linter.POJO.DO.Likes;
import linter.service.LikesService;
import linter.mapper.LikesMapper;
import linter.utils.PropertyUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

import static linter.custom.CustomResultType.LIKES_ERROR;
import static linter.custom.CustomResultType.LIKES_SUCCESS;

/**
* @author 北煜
* @description 针对表【likes(点赞情况表)】的数据库操作Service实现
* @createDate 2024-03-15 11:18:48
*/
@Service
public class LikesServiceImpl extends ServiceImpl<LikesMapper, Likes>
    implements LikesService {

    @Resource
    LikesMapper likesMapper;

    @Override
    public String updateUuid(Long uuid, Integer postsId) {
        Date date = new Date();
        Likes likes = new Likes();
        likes.setUuid(uuid);
        likes.setPostsId(postsId);
        likes.setCreateTime(date);
        likes.setUpdateTime(date);
        int flag = likesMapper.insert(PropertyUtils.doToDto(likes, Likes.class));
        if (flag != 1) {
                return LIKES_ERROR;
        }
        return LIKES_SUCCESS;
    }

    @Override
    public String updateLikeByUuid(Long uuid, Integer postsId) {
        return likesMapper.updateLikeByUuid(uuid, postsId) == 1 ? "取消点赞成功" : "取消点赞失败";
    }
}



